function submitCommentForm(ev) {
    ev.preventDefault();
    $("#submitCommentForm").attr('disabled', 'disabled');
    var dataString = $('#commentForm').serialize();
    $.ajax(
            {
                type: "POST",
                data: dataString,
                url: $("#commentForm").attr("action"),
                success: function (result) {
                    $("#commentscontainer").html(result);
                    $("#commentbox").html('');
                    $("#commentForm").submit(submitCommentForm);
                },
                error: function (result) {
                    $("#submitCommentForm").removeAttr('disabled');
                }
            });
}
function printPage(ev) {
    ev.preventDefault();

    var css = document.styleSheets[0];
    var cssRules = css.cssRules;
    if (cssRules) {
        for (var i = 0; i < cssRules.length; i++) {
            var rule = cssRules[i];

            if (rule.media && rule.media.mediaText == 'print') {
                for (var j = 0; j < rule.cssRules.length; j++) {
                    css.insertRule(rule.cssRules[j].cssText, cssRules.length);
                }
                break;
            }
        }
    }

    window.print();
}
function logout(ev) {
    ev.preventDefault();
    $("#logoutForm").submit();
}

$(function () {
    $("#search")
    .each(function (ev) {
        $(this).data("default", $(this).val());
    })
    .focus(function (ev) {
        if ($(this).val() == $(this).data("default")) {
            $(this).val('');
        }
    })
    .blur(function (ev) {
        if ($(this).val() == "") {
            $(this).val($(this).data("default"));
        }
    });

  

    $("#commentForm").submit(submitCommentForm);

    $("#printButton").click(printPage);

    $("#logoutLink").click(logout);
   

    
});